import type { BaseController } from '../BaseAppliance/definition'

/**
 * 当前家电详情页的 Controller
 */
const controllers = new Map<string, BaseController.Control>()
// let currentContextHaId = '' // 当前上下文对应的 haId

export function setControllerContext<TController extends BaseController.Control>(controller: TController): void {
  const haId = controller.store._datasource.haId
  // currentContextHaId = haId
  controllers.set(haId, controller)
}

export function removeControllerContext(haId: string): void {
  controllers.delete(haId)
}

export function getControllerContext<TController extends BaseController.Control>(haId: string): TController | null {
  return (controllers.get(haId) as TController | undefined) || null
}

// export function getCurrentControllerContext<TController extends BaseController.Control>(): TController | null {
//   return (controllers.get(currentContextHaId) as TController | undefined) || null
// }
